package com.example.music.controller;

import com.example.commonutils.R;
import com.example.music.model.request.CollectRequest;
import com.example.music.service.CollectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName AdminController
 * @Author: wx
 * @Create: 2022-10-04  17:12
 * @Description TODO
 * @Version: 1.0
 **/
@Api(description="收藏歌曲等操作")
@RestController
@CrossOrigin //解决跨域问题
public class CollectController {

    @Autowired
    private CollectService collectService;


    /**
     * 添加收藏的歌曲
     **/
    @ApiOperation("添加收藏歌曲")
    @PostMapping("/collection/add")
    public R addCollection(@RequestBody CollectRequest addCollectRequest) {
        return collectService.addCollection(addCollectRequest);
    }
    //TODO  这些其实有点偏简单的逻辑  所以就一点 所以放在外面  拿到里面
    // 取消收藏的歌曲
    @ApiOperation("取消收藏歌曲")
    @DeleteMapping("/collection/delete")
    public R deleteCollection(@RequestParam Integer userId, @RequestParam Integer songId) {
        return collectService.deleteCollect(userId, songId);
    }

    @ApiOperation("是否收藏歌曲")
    @PostMapping("/collection/status")
    public R isCollection(@RequestBody CollectRequest isCollectRequest) {
        return collectService.existSongId(isCollectRequest);

    }

    // 返回的指定用户 ID 收藏的列表
    @ApiOperation("返回的指定用户 ID 收藏的列表")
    @GetMapping("/collection/detail")
    public R collectionOfUser(@RequestParam("userId") Integer userId) {
        return collectService.collectionOfUser(userId);
    }
}
